import navMenuTpl from './navMenu.html';

function navMenu($compile) {
  'ngInject';

  return {
    restrict: 'E',
    scope: {
      menu: '<',
    },
    replace: true,
    templateUrl: navMenuTpl,
    compile(tElement, tAttrs) {
      return function link($scope, iElement, iAttrs, controller, transclude) {
        $scope.toggle = (menu) => {
          if (menu.children) {
            menu.isExpanded = !menu.isExpanded;
          }
          if (menu.stateName) {
            menu.active = true;
          }
        };
      };
    },
  };
}

export default navMenu;
